package HelloServiceDo

import (
	"github.com/neo4j/neo4j-go-driver/v4/neo4j"
	"goGrpc/helloService/DataBaseUtils"
	"log"
)

func MyHelloNeo4j() {
	session := DataBaseUtils.Neo4jConnection.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeWrite})
	log.Printf("neo4j会话创建成功, %v \n", session)
	defer session.Close()
	greeting, err := session.WriteTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
		result, err := transaction.Run(
			"CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)",
			map[string]interface{}{"message": "hello, world"})
		if err != nil {
			return nil, err
		}
		if result.Next() {
			log.Printf("neo4j写入成功！ %v \n", result.Record().Values[0])
			return result.Record().Values[0], nil
		}
		return nil, result.Err()
	})
	if err != nil {
		log.Printf("neo4j写入异常！ %v \n", err)
	}
	log.Printf("neo4j写入成功！ %v \n", greeting.(string))
}
